 
var app = getApp()
Page({
  data: {
    toastHidden: true,
    city_name: '',
    opacity: 0.4,
    disabled: true,
    message: "",
    name: "",
    userInput:"",
  },
  change: function (e) {
    //当有输入时激活发送按钮，无输入则禁用按钮
    if (e.detail.value != "") {
      this.setData({
        message: e.detail.value,
        opacity: 1,
        disabled: false,
      })
    } else {
      this.setData({
        message: "",
        opacity: 0.4,
        disabled: true,
      })
    }
  },
  chang: function(e){
    if (e.detail.value != "") {
      this.setData({
        name: e.detail.value,
        opacity: 1,
        
      })
    } else {
      this.setData({
        name: "匿名",
        opacity: 0.4,
        
      })
    }
  },
  send: function () {
    var that = this
   
    var message = this.data.message
    
    if(this.data.name==""){
      that.setData({
        name:"匿名"
      })
    }
    var name=this.data.name
    var time = Date.parse(new Date());
    time = time / 1000;
    // console.log(timestamp);



    const requestTask = wx.request({
      url: 'http://139.199.105.136/lovewall/insert_first', 
      header: {
        'Content-type': 'application/json',
      },
      //method: "POST",
      data: {
        //'time':time,
        'message':message,
        'name':name
        },
        success:function(res){
          console.log(res.data);
          
          that.setData({
            userInput: ''
          })
          app.globalData.bo=true;
          wx.switchTab({
            url: '../index/index',
          })
        },

      complete: function (res) {
        
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
      }
    })
    
  },  
  onToastChanged: function () {
    that.setData({ toastHidden: true });
  },
  //分享
  onShareAppMessage: function () {

  }
})
var that;
 